import datetime
import json
from django.test import TestCase


# Create your tests here.
from gitproject.models import Log, Branch, NickName, User, Project


class TestGit(TestCase):
    def everyday_everyone_remove(self, from_date, to_date, project, users):
        response = self.client.get('/gitproject/everyday_everyone_remove', {
            "from_date": from_date,
            "to_date": to_date,
            "project": project,
            "users": users
        })
        self.assertEqual(200, response.status_code)
        result = json.loads(response.content)
        return result.get('result')

    def test_git(self):
        project = Project()
        project.save()

        branch = Branch()
        branch.branch_name = 'TTJD'
        project_id = Project.objects.all()[0].id
        branch.project_id = project_id
        branch.save()

        nick = NickName()
        nick.nickname = 'test'
        nick.save()

        user = User()
        nick_id = NickName.objects.all()[0].id
        user.nickname_id = nick_id
        user.save()

        log = Log()
        log.datetime = datetime.datetime.now()
        branch_id = Branch.objects.all()[0].id
        log.branch_id = branch_id
        log.files = 20
        log.add = 30
        log.remove = 40
        user_id = User.objects.all()[0].id
        log.author_id = user_id
        log.save()

        self.everyday_everyone_remove('2015-12-01', '2015-12-20', '1,2,3', '1,2,3')
